//
//  MSMessage.m
//  MFWSDK
//
//  Created by BigPolarBear on 13-2-28.
//  Copyright (c) 2013年 mafengwo.com. All rights reserved.
//

#import "MSMessage.h"




@interface MSMessage()

@end

@implementation MSMessage

+(MSMessage*)messageWithDictionary:(NSDictionary*)dict
{
    if (!dict || dict.allKeys.count == 0) {
        return nil;
    }
    
//    MSMessage* msg = [[[MSMessage alloc]init]autorelease];
    MSMessage* msg = [[self alloc]init];
    msg.source = [NSMutableDictionary dictionaryWithDictionary:dict];

    return msg;
}

-(id)initWithMessage:(MSMessage*)message
{
    self = [super init];
    if (self) {
        self.source = message.source;
    }
    return self;
}

-(BOOL)isRead
{
    NSString* isReadInSource = [self.source objectForKey:MSMessageKeyIsRead];
    return [isReadInSource boolValue];
}

-(NSString*)msgId
{
    return [self.source stringValueForKey:MSMessageKeyMessageId];
}
-(NSString*)msgType
{
    return [self.source stringValueForKey:MSMessageKeyMessageType];
}
-(NSString*)msgContent
{
    return [self.source stringValueForKey:MSMessageKeyMessageContent];
}
-(NSString*)timestamp
{
    return [self.source stringValueForKey:MSMessageKeyMessageTimestamp];
}

-(NSString*)msgUname
{
    NSString *name = [self.source stringValueForKey:MSMessageKeyMessageUname];
    if ([name length] == 0)
    {
        name = @"旅游攻略";
    }
    return name;
}
-(NSString*)msgTitle
{
    NSString *title = [self.source stringValueForKey:MSMessageKeyMessageTitle];
    if ([title length] == 0)
    {
        title = [self defalutTitle];
    }
    return title;
}

- (NSString*)msgIcon
{
    return [self.source stringValueForKey:MSMessageKeyMessageIcon];
}
-(NSString*)url
{
    return [self.source stringValueForKey:@"url"];
}

- (NSString*)defalutTitle
{
    return @"系统消息";
}

-(NSString*)description
{
    return self.source.description;
}

-(NSComparisonResult)compareTimeStamp:(MSMessage *)otherMessage
{
    if([self.timestamp integerValue] < [otherMessage.timestamp integerValue])
    {
        return NSOrderedAscending;
    }
    else if([self.timestamp integerValue] == [otherMessage .timestamp integerValue])
    {
        return NSOrderedSame;
    }else
    {
        return NSOrderedDescending;
    }
}

@end
